#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "gamemain.h"

#if defined(_CONSOLE_APP)

int wmain( int argc, wchar_t *argv[ ], wchar_t *envp[ ] )
{
	gecko::RegisterThread(gtapi::GetThreadID());
	gtMain(argc, argv);
	return 0;
}

#else

int WINAPI WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR lpCmdLine, int /*nCmdShow*/ )
{	
	int numArgs = 0;
	char* mCmdArgs[256];

	//gtapi::RegisterThread(gtapi::GetThreadID());

	// convert command line into normal format (bloody windows!)-----
	int start = 0;
	size_t len = strlen(lpCmdLine);
		
	for ( unsigned int i = 0; i < len + 1; i++ )
	{
		if ( lpCmdLine[i] == ' ' || lpCmdLine[i] == 0 )
		{
			mCmdArgs[numArgs] = (lpCmdLine + start);
			lpCmdLine[i] = 0;

			numArgs++;
				
			start = i + 1;
		}
	}
	//---------------------------------------------------------------

 	FSMain(numArgs, mCmdArgs);

//#if defined(_DEBUG)
//	Platform::AssertOnMemoryLeaks();
//#endif

	//_CrtDumpMemoryLeaks();

	return 0;
}

#endif